'use strict';

const BaseController = require('../../base')

class Controller extends BaseController {
    constructor(...arg) {
        super(...arg)
        this.serviceName = 'role'
        this.modelName = 'system'
    }

    async changeRoleStatus() {
        const { ctx, service } = this;
        let query = {
            status: ctx.request.body.status
        }
        const id = ctx.helper.parseInt(ctx.request.body.id)
        const result = await service[this.app.config.public].admin[this.modelName][this.serviceName].updateStatus(query,{id})
        if (result) {
            ctx.returnBody(null, 100030);
        } else {
            ctx.returnBody(null, 100031, 500);
        }
    }
    // 查询
    async index() {
        const {ctx, service} = this;
        // console.log(ctx.state.user.createdBy, 111111111111111111111)
        const query = {
            limit: ctx.helper.parseInt(ctx.query.pageSize),
            offset: ctx.helper.parseInt(ctx.query.pageNum),
            roleName: ctx.query.roleName,
            status: ctx.query.status,
            createdBy: ctx.state.user.id === 1 ? null : ctx.state.user.userName
        }
        const result = await service[this.app.config.public].admin[this.modelName][this.serviceName].findList(query, [['roleSort', 'ASC']]);
        ctx.returnBody(result, 100010);
    }
}

module.exports = Controller;